package com.buyingtickets.controller;

import com.buyingtickets.entity.QueryParameter;
import com.buyingtickets.entity.Site;
import com.buyingtickets.entity.Type;
import com.buyingtickets.entity.User;
import com.buyingtickets.service.AdminPowerBiz;
import com.buyingtickets.service.SiteService;
import com.buyingtickets.service.TypeBiz;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author czl
 * @version 1.0
 * @description: TODO
 * @date 2021/7/1 9:49
 */


    @Controller
    @RequestMapping("power")
    public class AdminPowerController {
        @Resource
        private AdminPowerBiz adminPowerBiz;
@Resource
private TypeBiz typeBiz;
        @RequestMapping("query")
        public String power(QueryParameter qp, Model model){
            System.out.println(qp);
            List<User> usersList=adminPowerBiz.queryByQueryUser(qp);
            model.addAttribute("usersList",usersList);
            model.addAttribute("qp",qp);
            return "admin_power";
        }

        @RequestMapping("{page}/{yhid}/{yhm}/{name}/{phone}/fenye")
        public String fenye(@PathVariable int page,@PathVariable String yhid, @PathVariable String yhm, @PathVariable String name, @PathVariable String phone, Model model){
            System.out.println(page+" "+yhid+" "+yhm+" "+name+" "+phone);
            QueryParameter qp=new QueryParameter();
            if (!"!".equals(page)) {
                qp.setPage(page);
            }
            if (!"!".equals(yhid)) {
                qp.setYhid(yhid);
            }
            if (!"!".equals(yhm)) {
                qp.setYhm(yhm);
            }
            if (!"!".equals(name)) {
                qp.setName(name);
            }
            if (!"!".equals(phone)) {
                qp.setPhone(phone);
            }

            return power(qp,model);
        }
        @RequestMapping("power_details/{id}")
        public String site_details(@PathVariable int id, Model model){
            User user=adminPowerBiz.queryByID(id);
            List<Type> types=typeBiz.queryByCalss("用户类型");
            model.addAttribute("user",user);
            model.addAttribute("types",types);
            return "admin_power_details";
        }


        @RequestMapping(value = "update",method = RequestMethod.POST)
        @ResponseBody
        public int update(User user){
            System.out.println(user);
            return adminPowerBiz.update(user);
        }



}
